<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        // 定义两种格式的json字符串数据
        // 1. 对象格式json字符串
        var sJson1 = '{"name":"李四","age":20}';
        // 把json字符串转成javascript对象，通过对象的方式访问对象的属性
        var oPerson1 = JSON.parse(sJson1);
        alert(oPerson1.name);
        alert(oPerson1.age);

        // 2. 数组格式json字符串
        var sJson2 = '[{"name":"张三","age":20},{"name":"李四","age":22}]';
        var oPersonList = JSON.parse(sJson2);
        alert(oPersonList.length);
        var oPerson2 = oPersonList[1];
        alert(oPerson2.name + oPerson2.age);
    </script>
</head>
<body>
    
</body>
</html>